﻿using System;
using Communication.Message.Util;

namespace Communication.Message.FpgaUpdate
{
    // Token: 0x02000011 RID: 17
    public class NormalMessage : FlashUpdateChannelMessage
    {
        // Token: 0x060000D4 RID: 212 RVA: 0x00003084 File Offset: 0x00001284
        public NormalMessage(byte desId, byte funCode, byte[] datas, int dataLen, int offset, int totalRecTimeoutMillis, int spaceRecTimeoutMillis, int sendTimeoutMillis) : base(desId, funCode, datas, dataLen, offset, totalRecTimeoutMillis, spaceRecTimeoutMillis, sendTimeoutMillis)
        {
        }

        /// <summary>
        /// 处理接收数据报文
        /// </summary>
        /// <returns></returns>
        protected override bool DealwithReceiveMsg()
        {
            if (!base.IdentifyFrame())
            {
                return false;
            }
            int num = this.receiveBuffer.ReaderIndex();
            int @ushort = (int)this.receiveBuffer.GetUshort(num + 3);
            short @short = this.receiveBuffer.GetShort(num + 5 + @ushort);
            short num2 = CrcUtil.Crc16(this.receiveBuffer.Array(), this.receiveBuffer.ReaderIndex(), 5 + @ushort, CrcType.High_Low);
            if (@short != num2)
            {
                this.SetFailure(new CrcRrrorException());
                return true;
            }
            if (Enum.IsDefined(typeof(FlashUpdateErrorCode), (uint)this.receiveBuffer.GetByte(num + 5)))
            {
                this.errorCode = (FlashUpdateErrorCode)Enum.Parse(typeof(FlashUpdateErrorCode), this.receiveBuffer.GetByte(num + 5).ToString()); //有个错误码的比重
                base.SetSuccess();
                return true;
            }
            this.SetFailure(new IllegalErrorCodeException());
            return true;
        }
    }
}
